import request from './request.js'

// 登陆验证
const logining = function (user = {}) {
    return request.post("login", user)
}
// home页面左侧导航栏
const doMenus = function () {
    return request.get("menus");
}

// 用户列表请求
const getUsers = function (params = {}) {
    return request.get("users", {
        params
    })
}
// 用户管理状态修改
const getUsersState = function (uid, type) {
    return request.put(`users/${uid}/state/${type}`)
}
// 用户数据删除
const deleteUsers = function (uid) {
    return request.delete(`users/${uid}`)
}
//用户已存在信息修改
const reviseUsers = function (uid, params) {
    return request.put(`users/${uid}`, {
        params
    })
}
// 用户新增
const increaseUsers = function (params = {}) {
    return request.post("users", params)
}
// 用户分配权限
const reviseRolesUsers = function (uid, rid) {
    return request.put(`users/${uid}/role`, { rid })
}


// 角色列表展示
const getRoles = function () {
    return request.get("roles")
}
// 角色已存在信息修改
// const reviseRoles = function (uid, params) {
//     return request.put(`roles/${uid}`,
//         params
//     )
// }
// 角色信息删除
const deleteRoles = function (uid) {
    return request.delete(`roles/${uid}`)
}
//角色新增
const increaseRoles = function (params = {}) {
    return request.post("roles", params)
}
// 角色权限分配
const reviseRoles = function(uid){
    return request.post(`roles/${uid}`)
}
// 权限列表展示
const getRigths = function (type = "list") {
    return request.get(`rights/${type}`)
}
// 商品列表展示
const getGoods = function (params = {}) {
    return request.get("goods", {
        params
    })
}
// 商品分类数据列表
const getCategories = function (params = {}) {
    return request.get("categories", {
        params
    })
}
// 分类参数获取
const getCatParams = function (cid,sel='many') {
    return request.get(`categories/${cid}/attributes`, {
        params:{
            sel
        }
    })
}
// 订单数据列表
const getOrders = function (params = {}) {
    return request.get("orders", {
        params
    })
}
const API = {
    logining, doMenus,
    getUsers, getUsersState, deleteUsers, reviseUsers, increaseUsers, reviseRolesUsers,
    getRoles, reviseRoles, deleteRoles, increaseRoles,
    getRigths,
    getGoods,
    getCategories,getCatParams,
    getOrders,

}
export default {
    ...API,
    install(Vue) {
        Vue.prototype.$api = API
    }
}